//
//  HMStatusToolBar.swift
//  Weibo
//
//  Created by 黄亦寒 on 2016/9/24.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit
//底部工具栏
class HMStatusToolBar: UIView {

    //绑定数据
    var statusViewModel:HMStatusViewModel? {
        didSet {
            retweetButton.setTitle(statusViewModel?.retweetCount, for: .normal)
            commentButton.setTitle(statusViewModel?.commentcount, for: .normal)
            uilikeButton.setTitle(statusViewModel?.unlikecount, for: .normal)
        }
    }
    
    //转发按钮
    private lazy var retweetButton:UIButton = self.addChildButton(imageName: "timeline_icon_retweet", title: "转发")
    //评论按钮
    private lazy var commentButton:UIButton = self.addChildButton(imageName: "timeline_icon_comment", title: "评论")
    //赞按钮
    private lazy var uilikeButton:UIButton = self.addChildButton(imageName: "timeline_icon_unlike", title: "赞")
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置控件
    func setUpUI() {
        
        
        //竖线
        let firstLineView = addChildLineView()
        let secondLineView = addChildLineView()
        
        //设置约束
        retweetButton.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            
        }
        
        commentButton.snp_makeConstraints { (make) in
            make.left.equalTo(retweetButton.snp_right)
            make.top.bottom.equalTo(retweetButton)
            make.width.equalTo(retweetButton)
        }
        
        uilikeButton.snp_makeConstraints { (make) in
            make.left.equalTo(commentButton.snp_right)
            make.top.bottom.equalTo(commentButton)
            make.right.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        firstLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_right)
            make.centerY.equalTo(self)
        }
        
        secondLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp_right)
            make.centerY.equalTo(self)
        }
    }

    //设置按钮的方法
    private func addChildButton(imageName:String,title:String) -> UIButton{
        let button = UIButton()
        button.setImage(UIImage(named:imageName), for: .normal)
        button.setTitle(title, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        //去掉高亮效果
        button.adjustsImageWhenHighlighted = false
        addSubview(button)
        return button
        
    }
    
    //添加竖线的方法
    private func addChildLineView() ->UIImageView {
        let imageView = UIImageView(image:UIImage(named:"timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }
}
